#include "loadedlib.hpp"

using namespace Utils;

LoadedLib* LoadedLib::Factory::New(const std::string& filepath)
{
  LoadedLib* newLib = 0;
  LIBTYPE    lib    = dlopen(filepath.c_str(), RTLD_LAZY);
  
  if (!(lib))
    std::cerr << dlerror() << std::endl;
  else
    newLib = new LoadedLib(lib);
  return (newLib);
}

LoadedLib::LoadedLib(LIBTYPE lib) : lib(lib)
{
  error = 0;
}

LoadedLib::~LoadedLib(void)
{
  dlclose(lib);
}

const char*     LoadedLib::GetLastError(void) const
{
  return (error);
}
